package com.jonsion.service.impl;

import java.util.List;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jonsion.dao.IAccountDao;
import com.jonsion.dao.mapper.AccountMapper;
import com.jonsion.dao.mapper.SiteMapper;
import com.jonsion.domain.Account;
import com.jonsion.domain.Site;
import com.jonsion.exception.CustomException;
import com.jonsion.service.IAccountService;
import com.jonsion.service.ISiteService;
import com.jonsion.util.MD5;
import com.jonsion.util.StringUtil;
import com.jonsion.web.controller.AccountController;

@Service(value="siteService")
@Transactional
public class SiteServiceImpl implements ISiteService {
	protected static final Logger logger = LoggerFactory
	.getLogger(SiteServiceImpl.class);
	
	@Inject 
    private SiteMapper siteMapper; 
	
	
	
	
	@Transactional
	public Site add(Site ac)  throws CustomException{
		// TODO Auto-generated method stub
		try {
			List<Site> ls=siteMapper.getSiteByUserName(ac);
			
			if(ls==null || ls.size()==0){
				
				
				siteMapper.add(ac);
				
			}else{
				
				throw  new CustomException("もう存在した");
				
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}


	public List<Site> list()  throws CustomException{
		// TODO Auto-generated method stub
		boolean flag=false;
		try {
			List<Site> ls=siteMapper.list();
			
			return ls;
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw  new CustomException("ユーザを取る時にエラーが発生した",e);
		}
		
		return null;
	}
	

}
